#!/usr/bin/env python
# -*- coding:utf-8 -*-

__author__ = 'Bane'
__date__ = '15-4-27'
__contact__ = 'banezhang@zoho.com'
__copyright__ = 'Copyright (C) 2015, bane.im'

L = [1, 2, 4, 8, 16, 32, 64]
X = 5
found = False
i = 0
while not found and i < len(L):
    if 2 ** X == L[i]:
        found = True
    else:
        i = i + 1
if found:
    print('at index', i)
else:
    print(X, 'not found')

# while ... else
i = 0
while i < len(L):
    if 2 ** X == L[i]:
        print('at index', i)
        break
    i += 1
else:
    print(X, 'not found')

# for ... else
for l in L:
    if 2 ** X == l:
        print('at index', L.index(l))
        break
else:
    print(X, 'not found')

# in
if 2 ** X in L:
    print('at index', L.index(2 ** X))
else:
    print(X, 'not found')

L = []
for X in range(7):
    L.append(2 ** X)
print(L)

L = [2 ** X for X in range(7)]
print(L)

L = map(lambda x: 2**x, range(7))
print(L)
